package cn.disicn.controller;

import java.util.Date;
import org.apache.commons.lang3.StringUtils;
import cn.disicn.common.Const;
import cn.disicn.common.ServerResponse;
import cn.disicn.model.AppSystemHelp;
import cn.disicn.model.SecAdminUser;
import cn.disicn.util.IDUtil;
import com.jfinal.core.Controller;

/**
 * @author zjk
 * @date 2018年1月2日 下午3:56:02
 * @desc app内容帮助c
 * 
 */
public class AppSystemHelpController extends Controller {

	private static final AppSystemHelp appSystemhelp = new AppSystemHelp();
	private static final SecAdminUser secAdminuser = new SecAdminUser();

	/**
	 * 
	 * @desc 查询app任务帮助内容
	 */
	public void index() {
		Integer pageNum = getParaToInt("pageNum");
		Integer pageSize = getParaToInt("pageSize");
		if (pageNum != null && pageSize != null && pageNum > 0 && pageSize > 0) {
			renderJson(appSystemhelp.getAppSystemHelpList(pageNum, pageSize));
			return;
		}
		renderJson(ServerResponse
				.createByErrorMsg(Const.ErrorResult.PARAMETER_ERROR));
	}

	/**
	 * 
	 * @desc 添加app内容帮助
	 */
	public void addAppSystemHelp() {
		String title = getPara("title");
		String content = getPara("content");
		String sortNum = getPara("sortNum");
		String code = getPara("code");
		if (!StringUtils.isBlank(title) && !StringUtils.isBlank(content)
				&& !StringUtils.isBlank(sortNum) && !StringUtils.isBlank(code)) {
			ServerResponse<String> response = secAdminuser.valiImgCode(code,
					getSession());
			if (response.isSuccess()) {
				appSystemhelp.setId(IDUtil.getId());
				appSystemhelp.setCreateTime(new Date());
				appSystemhelp.setTitle(title);
				appSystemhelp.setContent(content);
				appSystemhelp.setSortNum(Integer.parseInt(sortNum));
				renderJson(appSystemhelp.addAppSystemHelp(appSystemhelp));
			} else {
				renderJson(response);
			}
			return;
		}
		renderJson(ServerResponse
				.createByErrorMsg(Const.ErrorResult.PARAMETER_ERROR));
	}

	/**
	 * 
	 * @desc 删除app内容帮助
	 */
	public void delAppSystemHelp() {
		String id = getPara("id");
		if (!StringUtils.isBlank(id) && id.length() == 32) {
			renderJson(appSystemhelp.delAppSystemHelp(id));
			return;
		}
		renderJson(ServerResponse
				.createByErrorMsg(Const.ErrorResult.PARAMETER_ERROR));
	}
}
